<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Fetch a result row as an associative array, a numeric array, or both</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.cubrid-error.html">« cubrid_error</a></li>
      <li style="float: right;"><a href="function.cubrid-fetch-assoc.html">cubrid_fetch_assoc »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="cubridmysql.cubrid.html">CUBRID MySQL 兼容性函数</a></li>
    <li>Fetch a result row as an associative array, a numeric array, or both</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.cubrid-fetch-array" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_fetch_array</h1>
  <p class="verinfo">(PECL CUBRID &gt;=8.3.0)</p><p class="refpurpose"><span class="refname">cubrid_fetch_array</span> &mdash; <span class="dc-title">Fetch a result row as an associative array, a numeric array, or both</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-fetch-array-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>cubrid_fetch_array</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = CUBRID_BOTH</span></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
    The <span class="function"><strong>cubrid_fetch_array()</strong></span> function is used to get a
    single row from the query result and returns an array. The cursor
    automatically moves to the next row after getting the result.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.cubrid-fetch-array-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
  <dl>
   
    <dt>
<code class="parameter">result</code></dt>

    <dd>
<p class="para"><code class="parameter">Result</code> comes from a call to <span class="function"><a href="function.cubrid-execute.html" class="function">cubrid_execute()</a></span></p></dd>

   
   
    <dt>
<code class="parameter">type</code></dt>

    <dd>
<p class="para">Array type of the fetched result CUBRID_NUM, CUBRID_ASSOC,
      CUBRID_BOTH. If you need to operate the lob object, you can use CUBRID_LOB.</p></dd>

   
  </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-fetch-array-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">Returns an array of strings that corresponds to the fetched row, when process is successful.</p>
  <p class="para"><strong><code>false</code></strong>, when there are no more rows; NULL, when process is unsuccessful.</p>
  <p class="para">The type of returned array depends on how type is defined. By using CUBRID_BOTH (default), you&#039;ll get an array with both associative and number indices, and you can decide which data type to use by setting the <code class="parameter">type</code> argument. The <code class="parameter">type</code> variable can be set to one of the following values:</p>
    <ul class="simplelist">
        <li class="member">CUBRID_NUM : Numerical array (0-based)</li>
        <li class="member">CUBRID_ASSOC : Associative array</li>
        <li class="member">CUBRID_BOTH : Numerical &amp; Associative array (default)</li>
    </ul>  
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-fetch-array-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1188">
   <p><strong>示例 #1 <span class="function"><strong>cubrid_fetch_array()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$req&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;name,area,seats,address&nbsp;FROM&nbsp;stadium&nbsp;WHERE&nbsp;nation_code='GRE'&nbsp;AND&nbsp;seats&nbsp;&gt;&nbsp;10000"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-40s&nbsp;%-10s&nbsp;%-6s&nbsp;%-20s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"name"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"area"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"seats"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"address"</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CUBRID_NUM</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-40s&nbsp;%-10s&nbsp;%-6s&nbsp;%-20s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">3</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;if&nbsp;you&nbsp;want&nbsp;to&nbsp;operate&nbsp;LOB&nbsp;object,&nbsp;you&nbsp;can&nbsp;use&nbsp;cubrid_fetch_array($req,&nbsp;CUBRID_NUM&nbsp;|&nbsp;CUBRID_LOB)<br /><br /></span><span style="color: #0000BB">cubrid_close_request</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
name                                     area       seats  address             
Panathinaiko Stadium                     86300.00   50000  Athens, Greece      
Olympic Stadium                          54700.00   13000  Athens, Greece      
Olympic Indoor Hall                      34100.00   18800  Athens, Greece      
Olympic Hall                             52400.00   21000  Athens, Greece      
Olympic Aquatic Centre                   42500.00   11500  Athens, Greece      
Markopoulo Olympic Equestrian Centre     64000.00   15000  Markopoulo, Athens, Greece
Faliro Coastal Zone Olympic Complex      34650.00   12171  Faliro, Athens, Greece
Athens Olympic Stadium                   120400.00  71030  Maroussi, Athens, Greece 
Ano Liossia                              34000.00   12000  Ano Liosia, Athens, Greece
</pre></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.cubrid-fetch-array-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.cubrid-execute.html" class="function" rel="rdfs-seeAlso">cubrid_execute()</a> - Execute a prepared SQL statement</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-fetch.html" class="function" rel="rdfs-seeAlso">cubrid_fetch()</a> - Fetch the next row from a result set</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-fetch-row.html" class="function" rel="rdfs-seeAlso">cubrid_fetch_row()</a> - Return a numerical array with the values of the current row</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-fetch-assoc.html" class="function" rel="rdfs-seeAlso">cubrid_fetch_assoc()</a> - Return the associative array that corresponds to the fetched row</span></li>
   <li class="member"><span class="function"><a href="function.cubrid-fetch-object.html" class="function" rel="rdfs-seeAlso">cubrid_fetch_object()</a> - Fetch the next row and return it as an object</span></li>
   </ul>
  </p>
  </div>


</div></div></div></body></html>